from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-24 14:03:29.464391
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 24, May, 2022
Time: 14:03:37
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.4037
Nobs: 666.000 HQIC: -49.7763
Log likelihood: 8238.88 FPE: 1.90575e-22
AIC: -50.0120 Det(Omega_mle): 1.66653e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.309052 0.060024 5.149 0.000
L1.Burgenland 0.107869 0.038684 2.788 0.005
L1.Kärnten -0.109842 0.020329 -5.403 0.000
L1.Niederösterreich 0.202103 0.080556 2.509 0.012
L1.Oberösterreich 0.124359 0.079737 1.560 0.119
L1.Salzburg 0.255902 0.041135 6.221 0.000
L1.Steiermark 0.043223 0.053956 0.801 0.423
L1.Tirol 0.104242 0.043617 2.390 0.017
L1.Vorarlberg -0.063676 0.038550 -1.652 0.099
L1.Wien 0.031654 0.070542 0.449 0.654
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.042718 0.127774 0.334 0.738
L1.Burgenland -0.030099 0.082348 -0.366 0.715
L1.Kärnten 0.040382 0.043276 0.933 0.351
L1.Niederösterreich -0.181339 0.171482 -1.057 0.290
L1.Oberösterreich 0.448597 0.169739 2.643 0.008
L1.Salzburg 0.284516 0.087566 3.249 0.001
L1.Steiermark 0.107155 0.114858 0.933 0.351
L1.Tirol 0.313596 0.092849 3.377 0.001
L1.Vorarlberg 0.021552 0.082063 0.263 0.793
L1.Wien -0.039302 0.150165 -0.262 0.794
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183291 0.030820 5.947 0.000
L1.Burgenland 0.090282 0.019863 4.545 0.000
L1.Kärnten -0.007869 0.010438 -0.754 0.451
L1.Niederösterreich 0.257633 0.041362 6.229 0.000
L1.Oberösterreich 0.155959 0.040942 3.809 0.000
L1.Salzburg 0.042256 0.021121 2.001 0.045
L1.Steiermark 0.024153 0.027704 0.872 0.383
L1.Tirol 0.085509 0.022396 3.818 0.000
L1.Vorarlberg 0.052525 0.019794 2.654 0.008
L1.Wien 0.117236 0.036221 3.237 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110136 0.030847 3.570 0.000
L1.Burgenland 0.045872 0.019880 2.307 0.021
L1.Kärnten -0.014301 0.010447 -1.369 0.171
L1.Niederösterreich 0.185209 0.041398 4.474 0.000
L1.Oberösterreich 0.326863 0.040978 7.977 0.000
L1.Salzburg 0.102001 0.021140 4.825 0.000
L1.Steiermark 0.108958 0.027728 3.929 0.000
L1.Tirol 0.097441 0.022415 4.347 0.000
L1.Vorarlberg 0.059117 0.019811 2.984 0.003
L1.Wien -0.022235 0.036252 -0.613 0.540
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114678 0.057430 1.997 0.046
L1.Burgenland -0.044040 0.037013 -1.190 0.234
L1.Kärnten -0.046477 0.019451 -2.389 0.017
L1.Niederösterreich 0.140754 0.077076 1.826 0.068
L1.Oberösterreich 0.162765 0.076293 2.133 0.033
L1.Salzburg 0.281289 0.039358 7.147 0.000
L1.Steiermark 0.055160 0.051625 1.068 0.285
L1.Tirol 0.166053 0.041733 3.979 0.000
L1.Vorarlberg 0.094856 0.036885 2.572 0.010
L1.Wien 0.077143 0.067494 1.143 0.253
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060205 0.045329 1.328 0.184
L1.Burgenland 0.031945 0.029213 1.094 0.274
L1.Kärnten 0.051400 0.015352 3.348 0.001
L1.Niederösterreich 0.206996 0.060834 3.403 0.001
L1.Oberösterreich 0.318502 0.060216 5.289 0.000
L1.Salzburg 0.041160 0.031065 1.325 0.185
L1.Steiermark 0.007460 0.040746 0.183 0.855
L1.Tirol 0.131738 0.032939 3.999 0.000
L1.Vorarlberg 0.064981 0.029113 2.232 0.026
L1.Wien 0.086366 0.053272 1.621 0.105
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166579 0.054309 3.067 0.002
L1.Burgenland 0.007850 0.035001 0.224 0.823
L1.Kärnten -0.065009 0.018394 -3.534 0.000
L1.Niederösterreich -0.092591 0.072887 -1.270 0.204
L1.Oberösterreich 0.206417 0.072147 2.861 0.004
L1.Salzburg 0.053592 0.037219 1.440 0.150
L1.Steiermark 0.240360 0.048820 4.923 0.000
L1.Tirol 0.501157 0.039465 12.699 0.000
L1.Vorarlberg 0.058775 0.034881 1.685 0.092
L1.Wien -0.075051 0.063827 -1.176 0.240
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148314 0.060281 2.460 0.014
L1.Burgenland 0.003694 0.038850 0.095 0.924
L1.Kärnten 0.059925 0.020417 2.935 0.003
L1.Niederösterreich 0.181913 0.080902 2.249 0.025
L1.Oberösterreich -0.054821 0.080080 -0.685 0.494
L1.Salzburg 0.206059 0.041312 4.988 0.000
L1.Steiermark 0.134145 0.054188 2.476 0.013
L1.Tirol 0.071406 0.043804 1.630 0.103
L1.Vorarlberg 0.142551 0.038716 3.682 0.000
L1.Wien 0.108535 0.070845 1.532 0.126
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374263 0.035548 10.529 0.000
L1.Burgenland -0.000400 0.022910 -0.017 0.986
L1.Kärnten -0.022028 0.012040 -1.830 0.067
L1.Niederösterreich 0.217058 0.047707 4.550 0.000
L1.Oberösterreich 0.227607 0.047223 4.820 0.000
L1.Salzburg 0.039177 0.024361 1.608 0.108
L1.Steiermark -0.016373 0.031954 -0.512 0.608
L1.Tirol 0.095373 0.025831 3.692 0.000
L1.Vorarlberg 0.053343 0.022831 2.336 0.019
L1.Wien 0.033770 0.041777 0.808 0.419
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037759 0.120737 0.174225 0.144263 0.101955 0.087688 0.041600 0.211932
Kärnten 0.037759 1.000000 -0.018465 0.134910 0.052729 0.090837 0.441432 -0.059927 0.093826
Niederösterreich 0.120737 -0.018465 1.000000 0.324416 0.132263 0.284665 0.078720 0.164253 0.301015
Oberösterreich 0.174225 0.134910 0.324416 1.000000 0.220323 0.309042 0.169120 0.151542 0.251841
Salzburg 0.144263 0.052729 0.132263 0.220323 1.000000 0.130510 0.098888 0.115631 0.130600
Steiermark 0.101955 0.090837 0.284665 0.309042 0.130510 1.000000 0.141380 0.120335 0.051773
Tirol 0.087688 0.441432 0.078720 0.169120 0.098888 0.141380 1.000000 0.071065 0.148580
Vorarlberg 0.041600 -0.059927 0.164253 0.151542 0.115631 0.120335 0.071065 1.000000 0.008349
Wien 0.211932 0.093826 0.301015 0.251841 0.130600 0.051773 0.148580 0.008349 1.000000